home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11935 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  100 lines

  1. Path: pop.gnn.com!HoangTQ
  2. From: Tuyen Hoang <HoangTQ@gnn.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Derived class not calling overloaded base class function
  5. Date: Sat, 16 Mar 1996 22:33:58
  6. Organization: GNN
  7. Message-ID: <4ig150$h3p@news-e2c.gnn.com>
  8. References: <4g46t2$3vd@otis.netspace.net.au> <4gk310$pqt@nuntius.u-net.net>
  9. NNTP-Posting-Host: www-29-26.gnn.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset="us-ascii"
  12. X-GNN-NewsServer-Posting-Date: 17 Mar 1996 03:32:48 GMT
  13. X-Mailer: GNNmessenger 1.2
  14.  
  15. First, I want appologize for the previous posting that occured by mistaken setting
  16. before I finish the.
  17.  
  18. TorrBoy@Netspace.net.au (Peter J. Torr) wrote:
  19. >
  20. >>Hi,
  21. >
  22. >>Hopefully a very simple question someone can answer for me!
  23. >
  24. >>I have a class, say 'foo' (everyone's favourite) which has a member
  25. > function 
  26. >>'int Get(void)'
  27. >
  28. >>I then derive a class (say 'goo') which has as a base class foo. If goo has
  29. > a 
  30. >>function also called Get, but with different params (say ''char *Get(char
  31. > *)') I can't 
  32. >>seem to get the base class' Get() function to operate within the derived
  33. > class.
  34. >
  35. >>If I say just plain "Get()" it says too few parameters (for Get(char *)".
  36. > If I use 
  37. >>"::Get()" the compiler complains Get should have a prototype. If I say
  38. > "foo.Get()" it 
  39. >>says improper use of typedef foo. The only way seems to be to explicitly
  40. > cast the 
  41. >>this pointer to a foo.
  42. >
  43. >>Surely there is a better way than this? Thanks for any help (e-mail
  44. > preferred)
  45. >
  46. >>Peter
  47. >
  48. In article <4gk310$pqt@nuntius.u-net.net> Thomas Christensen wrote:
  49.  
  50. >Hi Peter
  51. >
  52. >Have you tried foo::Get() ?
  53.  
  54. Hi Peter
  55.  
  56. This is an illustration
  57. goo agoo ;
  58. agoo.foo::Get(); // the base function foo::get() gets called
  59.  
  60. If you hate this syntax -I do- and want to use agoo.get() to call the base 
  61. class function, you need to do one *easy* thing: add an inline function into 
  62. your definition of derived class goo
  63.  
  64. class goo : public foo{
  65. //...
  66. void get() { foo::get() ; }
  67. //...
  68. };
  69.  
  70. that's all, but the _concept_is_not_easy_. If you want some explanation, you 
  71. should look back the thread and the FAQ. As my experience, I usually need an 
  72. illustration before I can understand the theorical explanation.
  73.  
  74. Then this is my question
  75.  
  76.     Do we need a more elegant way than this work around. I wonder to have a way to 
  77. say to the compiler that I do not declare a new function-inlining and calling 
  78. the base function- but notify that the base function is now _unhiding_ from 
  79. the derived overloaded function, something look like
  80.  
  81. class derived : public base{
  82. //....
  83.     public:
  84.        void get(int);
  85.   /* unhiding */ void base::get();
  86. //....
  87. };
  88.  
  89. the problem is not concern about one or more overhead calls but the concept 
  90. that the base function is now *explicit* present in the derived class and can 
  91. be overloaded as it was declared here. Does the virtual key word is 
  92. needed/no needed?
  93.  
  94.  
  95.  
  96. ____________________________________
  97. Hoang Tuyen Q.
  98. HoangTQ@gnn.com
  99.  
  100.